home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / dslibrary.lha / ds.library / test_prg / TestDSLib.c < prev   
C/C++ Source or Header  |  1997-02-13  |  4KB  |  110 lines

  1. /*
  2. **      $VER: TextDSLib.c 37.0 (30.01.97)
  3. **
  4. **      Demo program for ds.library
  5. **
  6. **      (C) Copyright 1997 Markus Hillenbrand
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include <exec/types.h>
  14. #include <libraries/ds.h>
  15.  
  16. #include <clib/ds_protos.h>
  17. #include <clib/exec_protos.h>
  18.  
  19. #include <pragma/ds_lib.h>
  20.  
  21. struct Library *DSBase = NULL;
  22.  
  23. /// Test for DS_BTree
  24.  
  25. #define KEYSIZE 7
  26.  
  27. typedef struct
  28.     {
  29.     char key[KEYSIZE];
  30.     char name[40];
  31.     } customer;
  32.  
  33. int mycompare(void *s1, void *s2)
  34. {
  35.     return strcmp((char *)s1,(char *)s2);
  36. }
  37.  
  38. void DS_BTree_Test()
  39. {
  40.     printf("B-Tree on Disk\n--------------\n\n");
  41.  
  42.     BTREE t;
  43.  
  44.     if (DS_BTreeOpen(&t,"RAM:1.tree",KEYSIZE, sizeof(customer), mycompare))
  45.         {
  46.         customer k1     = { "003001", "Markus Hillenbrand" };
  47.         customer k2      = { "000005", "Arnold Schwarzenegger" };
  48.         customer k3     = { "000201", "Bruce Willis" };
  49.         customer k4     = { "000003", "Claudia Schiffer" };
  50.         customer k5     = { "000401", "Naomi Cambell" };
  51.         customer k6     = { "020002", "Sylvester Stallone" };
  52.         customer k7     = { "000001", "Bill Clinton" };
  53.         customer k8     = { "103001", "Helmut Kohl" };
  54.         customer k9     = { "200005", "Boris Jelzin" };
  55.         customer kA        = { "300201", "Vincent van Gogh" };
  56.         customer kB      = { "500401", "Johann Sebastian Bach" };
  57.         customer kC     = { "500402", "Johann Wolfgang von Goethe" };
  58.         customer kD     = { "620002", "Donald Duck" };
  59.         customer kE     = { "700001", "Veronica Ferres" };
  60.  
  61.         if (!DS_BTreeInsert(t, k1.key, &k1)) printf("1 already in tree\n");
  62.         if (!DS_BTreeInsert(t, k2.key, &k2)) printf("2 already in tree\n");
  63.         if (!DS_BTreeInsert(t, k3.key, &k3)) printf("3 already in tree\n");
  64.         if (!DS_BTreeInsert(t, k4.key, &k4)) printf("4 already in tree\n");
  65.         if (!DS_BTreeInsert(t, k5.key, &k5)) printf("5 already in tree\n");
  66.         if (!DS_BTreeInsert(t, k6.key, &k6)) printf("6 already in tree\n");
  67.         if (!DS_BTreeInsert(t, k7.key, &k7)) printf("7 already in tree\n");
  68.         if (!DS_BTreeInsert(t, k8.key, &k8)) printf("8 already in tree\n");
  69.         if (!DS_BTreeInsert(t, k9.key, &k9)) printf("9 already in tree\n");
  70.         if (!DS_BTreeInsert(t, kA.key, &kA)) printf("A already in tree\n");
  71.         if (!DS_BTreeInsert(t, kB.key, &kB)) printf("B already in tree\n");
  72.         if (!DS_BTreeInsert(t, kC.key, &kC)) printf("C already in tree\n");
  73.         if (!DS_BTreeInsert(t, kD.key, &kD)) printf("D already in tree\n");
  74.         if (!DS_BTreeInsert(t, kE.key, &kE)) printf("E already in tree\n");
  75.  
  76.         if (!DS_BTreeDelete(t, k2.key )) printf("2 not deleted\n");
  77.         if (!DS_BTreeDelete(t, k7.key )) printf("7 not deleted\n");
  78.         if (!DS_BTreeDelete(t, k7.key )) printf("7 not deleted\n");
  79.  
  80.         if (DS_BTreeGetEntry(t,kC.key,&k1)) printf("Found \"%s\" for key \"%s\"\n", k1.name, kC.key);
  81.         if (DS_BTreeGetEntry(t,k3.key,&k1)) printf("Found \"%s\" for key \"%s\"\n", k1.name, k3.key);
  82.         if (DS_BTreeGetEntry(t,k6.key,&k1)) printf("Found \"%s\" for key \"%s\"\n", k1.name, k6.key);
  83.         if (DS_BTreeGetEntry(t,k2.key,&k1)) printf("Found \"%s\" for key \"%s\"\n", k1.name, k7.key);
  84.         if (DS_BTreeGetEntry(t,k7.key,&k1)) printf("Found \"%s\" for key \"%s\" (wrong !)\n", k1.name, k7.key); else printf("Found nothing for key %s, and that is correct.\n", k7.key);
  85.  
  86.         if (DS_BTreeGetEntry(t,"Hello ",&k1)) printf("Such a shit\n");
  87.  
  88.         DS_BTreeClose(t);
  89.         }
  90.     else printf("Could not open/create BTree on disk.\n");
  91. }
  92.  
  93. void main (int argc, char **argv)
  94. {
  95.     struct Task *task = FindTask(0);
  96.     
  97.     if (((long)task->tc_SPUpper-(long)task->tc_SPLower)>=20000)
  98.         {
  99.         DSBase = OpenLibrary("ds.library", 37);
  100.         if (DSBase)
  101.             {
  102.             DS_BTree_Test();
  103.  
  104.             CloseLibrary(DSBase);
  105.             }
  106.         else printf("Library not opened.\n");
  107.         }
  108.     else printf("Stack must be at least 20.000\n");
  109. }
  110.